﻿using MCInsertDb.DAL;
using SHANGBN1.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Linq;
using System.Text;

namespace SHANGBN1.DAL
{
    public class CKXXDAL
    {
        public string GetById()
        {
            DataTable dt = SqlHelper.ExecuteDataTable(@"select * from (select * from CKXX1 where numcount<1 order by ckh asc ) where rownum=1");
            if (dt.Rows.Count <= 0)
            {
                return null;
            }
            else if (dt.Rows.Count > 1)
            {
                throw new Exception("严重错误，查出多条数据！");
            }
            else
            {
                DataRow row = dt.Rows[0];
                string value = row[0].ToString();
                return value;
            }
        }

        public int UpdateAdd(int ckh)
        {
            int returnValue = 0;
            returnValue = SqlHelper.ExecuteNonQuery(@"UPDATE CKXX1
                        SET NUMCOUNT=NUMCOUNT + 1
                           where CKH=:CKH",
                new OracleParameter(":CKH", ckh));

            return returnValue;
        }
        public int UpdateSub(int ckh)
        {
            int returnValue = 0;
            returnValue = SqlHelper.ExecuteNonQuery(@"UPDATE CKXX1
                        SET NUMCOUNT=NUMCOUNT - 1
                           where CKH=:CKH",
                new OracleParameter(":CKH", ckh));

            return returnValue;
        }

        public string GetById_YELLOW()
        {
            DataTable dt = SqlHelper.ExecuteDataTable(@"select * from (select * from CKXX1_YELLOW where numcount<1 order by ckh asc ) where rownum=1");
            if (dt.Rows.Count <= 0)
            {
                return null;
            }
            else if (dt.Rows.Count > 1)
            {
                throw new Exception("严重错误，查出多条数据！");
            }
            else
            {
                DataRow row = dt.Rows[0];
                string value = row[0].ToString();
                return value;
            }
        }

        public int UpdateAdd_YELLOW(int ckh)
        {
            int returnValue = 0;
            returnValue = SqlHelper.ExecuteNonQuery(@"UPDATE CKXX1_YELLOW
                        SET NUMCOUNT=NUMCOUNT + 1
                           where CKH=:CKH",
                new OracleParameter(":CKH", ckh));

            return returnValue;
        }
        public int UpdateSub_YELLOW(int ckh)
        {
            int returnValue = 0;
            returnValue = SqlHelper.ExecuteNonQuery(@"UPDATE CKXX1_YELLOW
                        SET NUMCOUNT=NUMCOUNT - 1
                           where CKH=:CKH",
                new OracleParameter(":CKH", ckh));

            return returnValue;
        }
    }
}
